#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
#define NOKEY 0

int main()
{
	int keys_fd;	                 //按键句柄	
        char ret[2]; 
	struct input_event t;
      
        keys_fd = open("/dev/input/event2", O_RDONLY);
	if(keys_fd<=0)
	{
                fprintf(stdout, "open /dev/input/event0 device error!\n");
		return 0;
	}

	while(1)
	{	/*
                if(read(keys_fd,&t,sizeof(t))==sizeof(t)) {
		    if(t.type==EV_KEY)			//获取的是按键消息
			if(t.value==0 || t.value==1)    //返回值是1或者0
   			    fprintf(stdout, "key %d %s\n",t.code,(t.value)?"Pressed":"Released");     //1表按下，0表弹起
  		}*/

 		if(read(keys_fd,&t,sizeof(t))==sizeof(t)) {  
                    if (t.type == EV_KEY){  
                            printf("  type: EV_KEY, event = %s, value = %d \r\n",   
                                t.code == BTN_TOUCH ? "BTN_TOUCH" : "Unkown", t.value);   
 		    }else if(t.type == EV_REL){  
			    printf("  type: EV_REL, code = %d, value = %d \r\n", t.code, t.value);   
                    }else if(t.type == EV_ABS){  
                            printf("  type: EV_ABS, event = %s, value = %d \r\n",   
                           t.code == ABS_X ? "ABS_X" :   
                           t.code == ABS_Y ? "ABS_Y" :   
                           t.code == ABS_PRESSURE ? "ABS_PRESSURE" :"Unkown", t.value);  //该处使用了一些特殊的用法::   
                    }else{
                           printf("  type: %d\n", t.type);
		    }
		}
	}	
	close(keys_fd);
	
        return 0;
}

/*


#define EV_SYN 0x00
#define EV_KEY 0x01
#define EV_REL 0x02
#define EV_ABS 0x03
#define EV_MSC 0x04
#define EV_SW 0x05
#define EV_LED 0x11
#define EV_SND 0x12
#define EV_REP 0x14
#define EV_FF 0x15
#define EV_PWR 0x16
#define EV_FF_STATUS 0x17
#define EV_MAX 0x1f

*/

